package com.zzj.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzj.bean.AssembleBean;
import com.zzj.dao.AssembleDao;
import com.zzj.dao.ProductDao;
import com.zzj.utils.Result;
import com.zzj.utils.StatusCode;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AssembleServiceImpl implements AssembleService {
    @Resource
    private AssembleDao assembleDao;
    @Resource
    private ProductDao productDao;

    @Override
    public PageInfo<AssembleBean> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<AssembleBean> all = assembleDao.findAll();
        return new PageInfo<>(all);
    }

    @Override
    public Result updateAssemble(AssembleBean assembleBean) {
        assembleBean.setAstate("1");
        int i1 = assembleDao.updateAssemble(assembleBean);
        int i2 = productDao.updateStateByPid(assembleBean.getPid(), "11");
        if (i1 == 1 && i2 == 1){
            return new Result();
        }
        return new Result(false, StatusCode.ERROR,"操作失败");
    }

    @Override
    public List<AssembleBean> findByState(String astate) {
        List<AssembleBean> byState = assembleDao.findByState(astate);
        return byState;
    }
}
